//
//  TTCustomConfirmFooterView.m
//  TaoTuo
//
//  Created by LG on 2020/11/24.
//  Copyright © 2020 刘广. All rights reserved.
//

#import "TTCustomConfirmFooterView.h"
#import <YYTextView.h>
#import "TTLuoshiCellView.h"

@interface TTCustomConfirmFooterView ()

@property (nonatomic, strong) UILabel *titleLabel;
/// 收费标准
@property (nonatomic, strong) UIButton *standardBtn;
/// 关联石头 和 输入框的父视图
@property (nonatomic, strong) UIView *bgView;
@property (nonatomic, strong) YYTextView *textView;

/// 选好的石头
@property (nonatomic, strong) UIView *luoshiBGView;
@property (nonatomic, strong) TTLuoshiCellView *luoshiView;

@property (nonatomic, assign) CGFloat chooseBGViewH;
@property (nonatomic, assign) CGFloat luoshiBGViewH;
/// 从哪里选的 0: 从购物车查询, 1: 从订单查询
@property (nonatomic, assign) NSInteger type;

@end

@implementation TTCustomConfirmFooterView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        self.backgroundColor = UIColor.whiteColor;
        
        self.layer.cornerRadius = 10;
        self.layer.masksToBounds = YES;
        
        [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(chooseLuoshiFinished:) name:@"customChooseLuoshiFinishedNotifyKey" object:nil];
        
        [self setupSubviews];
        
    }
    return self;
}

- (void)chooseLuoshiFinished:(NSNotification *)notify
{
    TTCustomChooseLuoshiModel *model = notify.object;
    
    self.luoshiBGView.hidden = NO;
    self.bgView.hidden = YES;
    self.height = self.luoshiBGViewH;
    
    self.luoshiView.detailModel = model;
}

/// 查看收费标准
- (void)lookChargeStandard
{
    
}

/// 删除选中的石头
- (void)deleteLuoshiAction
{
    self.luoshiBGView.hidden = YES;
    self.bgView.hidden = NO;
    
    self.height = self.chooseBGViewH;
}

- (void)setupSubviews
{
    _titleLabel = [UILabel labelWithTitle:@"钻石定制信息（可选）" color:UIColorHex(#333333) font:[UIFont boldSystemFontOfSize:16]];
    [self addSubview:_titleLabel];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(12);
        make.top.mas_equalTo(20);
    }];
    
    NSString *btnTitle = @"代镶嵌收费标准";
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:btnTitle];
    [attr addAttributes:@{NSUnderlineStyleAttributeName : @1, NSStrokeColorAttributeName : UIColorHex(#FC832A), NSForegroundColorAttributeName : UIColorHex(#FC832A)} range:[btnTitle rangeOfAll]];
    _standardBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _standardBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    [_standardBtn setAttributedTitle:attr forState:UIControlStateNormal];
    [_standardBtn addTarget:self action:@selector(lookChargeStandard) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:_standardBtn];
    [_standardBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(self.mas_right).offset(-12);
        make.centerY.equalTo(self.titleLabel);
    }];
    
    [self setupBgViews];
    [self setupLuoshiBGView];
    
}

/// 从购买过的商品选
- (void)fromBuyGoodsChoose
{
    self.type = 1;
    if (self.fromBuyGoodsChooseBlock) {
        self.fromBuyGoodsChooseBlock();
    }

}

/// 从购物车选
- (void)fromGoodsCartChoose
{
    self.type = 0;
    if (self.fromGoodsCartChooseBlock) {
        self.fromGoodsCartChooseBlock();
    }

}

- (void)setupBgViews
{
    _bgView = [[UIView alloc] init];
    [self addSubview:_bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.titleLabel.mas_bottom).offset(20);
        make.left.right.equalTo(self);
        make.bottom.equalTo(self);
    }];
    
    [self layoutIfNeeded];
    
    UIImageView *imageView1 = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10, self.bgView.width - 20, 90)];
    imageView1.image = [UIImage imageNamed:@"关联订单"];
    [_bgView addSubview:imageView1];
    
    UIButton *btn1 = [UIButton createButtonWithTitle:@"关联已经购买钻石订单" titleColor:UIColorHex(#FD502D) titleFont:[UIFont boldSystemFontOfSize:15] backgroundColor:nil target:self action:@selector(fromBuyGoodsChoose)];
    btn1.frame = imageView1.frame;
    [_bgView addSubview:btn1];
    
    UIImageView *imageView2 = [[UIImageView alloc] initWithFrame:CGRectMake(10, imageView1.bottom + 15, self.bgView.width - 20, 90)];
    imageView2.image = [UIImage imageNamed:@"关联购物车"];
    [_bgView addSubview:imageView2];
    
    UIButton *btn2 = [UIButton createButtonWithTitle:@"购物车已经挑好的石头" titleColor:UIColorHex(333333) titleFont:[UIFont boldSystemFontOfSize:15] backgroundColor:nil target:self action:@selector(fromGoodsCartChoose)];
    btn2.frame = imageView2.frame;
    [_bgView addSubview:btn2];
    
    
    UILabel *fillinLabel = [UILabel labelTextCenterWithTitle:@"——— 以上都不满足，填写需求 ———" color:UIColorHex(666666) fontSize:14];
    fillinLabel.frame = CGRectMake(0, imageView2.bottom + 20, self.bgView.width, 30);
    [_bgView addSubview:fillinLabel];
    
    
    _textView = [[YYTextView alloc] initWithFrame:CGRectMake(10, fillinLabel.bottom + 10, self.bgView.width - 20, 142)];
    _textView.font = [UIFont systemFontOfSize:14];
    _textView.backgroundColor = UIColorHex(#F7F7F7);
    _textView.placeholderText = @"如果您有自己的石头，或者有需要业务员帮您配石头，或者其他特殊要求，请在这里写清楚需求。";
    _textView.layer.cornerRadius = 10;
    _textView.layer.masksToBounds = YES;
    [_bgView addSubview:_textView];
    
    
    UILabel *infoLabel = [UILabel labelWithTitle:@"填写后业务员会通过微信进一步跟您确认信息。" color:UIColorHex(#FC832A) fontSize:13];
    infoLabel.frame = CGRectMake(10, _textView.bottom + 5, self.bgView.width-20, 30);
    [_bgView addSubview:infoLabel];

    
    
    self.chooseBGViewH = infoLabel.bottom + 10 + 50;
    
    self.bgView.height = self.chooseBGViewH;
    
    self.height = self.chooseBGViewH;
    
}

- (void)setupLuoshiBGView
{
    
    [self layoutIfNeeded];
    
    
    _luoshiBGView = [[UIView alloc] initWithFrame:CGRectMake(0, self.titleLabel.bottom + 20, self.width, 100)];
    _luoshiBGView.hidden = YES;
    [self addSubview:_luoshiBGView];
    
    
    _luoshiView = [[TTLuoshiCellView alloc] initWithFrame:CGRectMake(10, 10, self.luoshiBGView.width - 20, 90)];
    [_luoshiBGView addSubview:_luoshiView];
    
    
    NSString *title = @"选错了，删除";
    NSMutableAttributedString *attr = [[NSMutableAttributedString alloc] initWithString:title];
    [attr addAttributes:@{NSUnderlineStyleAttributeName : @1, NSStrokeColorAttributeName : UIColorHex(#FC832A), NSForegroundColorAttributeName : UIColorHex(#FC832A)} range:[title rangeOfString:@"删除"]];
    
    UIButton *deleteBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [deleteBtn setTitleColor:UIColorHex(999999) forState:UIControlStateNormal];
    deleteBtn.titleLabel.font = [UIFont systemFontOfSize:15];
    [deleteBtn setAttributedTitle:attr forState:UIControlStateNormal];
    [deleteBtn addTarget:self action:@selector(deleteLuoshiAction) forControlEvents:UIControlEventTouchUpInside];
    [_luoshiBGView addSubview:deleteBtn];
    [deleteBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(_luoshiView.mas_bottom).offset(10);
        make.centerX.equalTo(self);
    }];
    
   
    [self layoutIfNeeded];
    
    self.luoshiBGViewH = deleteBtn.bottom + 10 + 50;
    
    self.luoshiBGView.height = self.luoshiBGViewH;
    self.luoshiBGView.hidden = self.luoshiBGViewH;
    
}


- (void)dealloc
{
    [[NSNotificationCenter defaultCenter] removeObserver:self];
}

@end
